<!-- <template>
  <div id="app">
    <router-view/>
  </div>
</template>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style> -->
<!--
 * @Description: 
 * @Author: tanggx
 * @Date: 2022-03-29 16:57:57
-->
<template>
  <!-- <a-config-provider :locale="zh_CN"> -->
    <div id="app" :class="{'isdefault':!isLarge,'isLarge':isLarge}">
      <router-view v-if="showRouter"></router-view>
      <LocalDebugLoginDialog v-if="!showRouter" ref="localDebugLoginDialog" @showRouter="showRouter = true" @finishLogin="finishLogin"></LocalDebugLoginDialog>
    </div>
  <!-- </a-config-provider> -->
</template>
<script>
import "../public/static/style.less";
import "../public/static/font/font.css";
import "../public/css/base.css";
import zh_CN from "ant-design-vue/lib/locale-provider/zh_CN";
import moment from "moment";
import "moment/locale/zh-cn";
import LocalDebugLoginDialog from "./views/components/LocalDebugLoginDialog.vue";
moment.locale("zh-cn");
export default {
  components: { LocalDebugLoginDialog },
  data() {
    return {
      showRouter: false,
      zh_CN,
      isLarge:false
    };
  },
  watch: {},
  created() {},
  mounted() {
    //判断当前的url是否为大屏的请求
    if(this.getUrlKey("isLarge",window.document.location.href)){
      this.isLarge=true;
    }
    if(this.getUrlKey("token",window.document.location.href)){
        var access_token = this.getUrlKey("token",window.document.location.href);
        localStorage.setItem("access_token", access_token)
    }
    if (this.$refs.localDebugLoginDialog.isDebug() && !localStorage.getItem("access_token")) {
      //本地调试模式
      this.$refs.localDebugLoginDialog.open();
      return;
    }
    //嵌入了agcloud的portal，这时候所有的授权啊401都不需要处理，只需要等token
    let waitToken = setInterval(() => {
      //agcloud会注入这个token，然后才会加载iframe
      let token = localStorage.getItem("access_token");
      if (token == undefined || token.length == 0) {
        this.$message.error("授权无效，请重新登陆！");
        clearInterval(waitToken);
        return;
      }
      //这里还需要拿到用户信息，这个接口是临时的，需求接口FIXME
      agcim.net.axiosWraper.getData(agcim.net.apiPath.curr_opus_login_user).then((res) => {
        let userInfo = res.content.user;
        this.finishLogin(userInfo);
      })
      clearInterval(waitToken);
    }, 1000);
  },
  methods: {
    getUrlKey(name, url) {
      const searchParams = new URLSearchParams(url.split('?')[1]);
      const value = searchParams.get(name);
      return value;
    },
    /**
     * @lastUpdateBy : 张瀚
     * @description: 完成了登陆，拿到了必要参数后，注入系统，显示主页
     * @param {token}
     * @param {userInfo}
     */
    finishLogin(userInfo) {
      localStorage.setItem("user", JSON.stringify(userInfo));
      //TODO:储存token获取时间
      localStorage.setItem("token_getTime", JSON.stringify(Date.now()));
      this.$store.commit("handleUserId", userInfo.userId);
      this.$store.commit("handleUserName", userInfo.userName);
      //有token，默认登录成功，至于token无效等情况，在接口调用后会退出到登录界面
      this.showRouter = true;
      console.log('完成登录');
    },
  },
};
</script>
<style lang="less">
 .isLarge{
  width: 100%;
  height: 100%;
  overflow:hidden;
 }
 .isdefault{
  width: 100%;
  height: 100%;
  overflow: hidden;
 }
 
#app {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
body {
  font-family: "MicrosoftYaHei" !important;
}
</style>

